package org.mathig.poker.action;

import org.mathig.poker.PlayerListener;
import org.mathig.poker.PlayerWrapper;
import org.mathig.poker.table.TableHand;

public class AllInAction extends PlayerAction {

	public AllInAction(PlayerWrapper player, TableHand tableHand) {
		super(player, tableHand);
	}

	public void execute() {
		int stack = tableHand.getTable().getStacks().removeTotal(player);
		logger.info("{} does all-in !", player);
		tableHand.getBets().add(player, stack);
		logger.debug("{}'s bet is now {}", player, tableHand.getBet(player));

		// fire event
		for (PlayerListener listener : tableHand.getPlayerListeners()) {
			if (listener != player)
				listener.playerAllIn(player.getPlayer(), tableHand);
		}
	}

}
